/*const reactiveHandler = {
    get(target, prop) {
        console.log('拦截了读取数据', prop)
        return Reflect.get(target, prop)
    },
    set(target, prop, val) {
        console.log('拦截了读取数据', prop)
        return Reflect.set(target, prop, val)
    },
    deleteProperty(target, prop) {
        return Reflect.deleteProperty(target, prop)
    }
}

function reactive(target) {
    if (target && typeof target === 'object') {
        if (Array.isArray(target)) {
            target.forEach((item, index) => {
                target[index] = reactive(target[item])
            })
        } else {
            Object.keys(target).forEach(key => {
                target[key] = reactive(target[key])
            })
        }
        return new Proxy(target, reactiveHandler)
    }
    return target
}

function debounce(fn, delay) {
    let timer = null
    return function () {
        clearTimeout(timer)
        timer = setTimeout(() => {
            timer = null
            fn.apply(this, arguments)
        }, delay)
    }
}

function throttle(fn, delay) {
    let lastTime = 0
    return function () {
        const nowTime = Date.now()
        if (nowTime - lastTime > delay) {
            fn.apply(this, arguments)
            lastTime = nowTime
        }
    }
}*/

const reactiveHandler = {
    get(target, prop) {
        Reflect.get(target, prop)
    },
    set(target, prop, val) {
        Reflect.set(target, prop, val)
    },
    deleteProperty(target, prop) {
        Reflect.deleteProperty(target, prop)
    }
}

const reactive = function (target) {
    if (target && typeof target === 'object') {
        if (Array.isArray(target)) {
            target.forEach((item, index) => {
                target[index] = reactive(target[item])
            })
        } else {
            Object.keys(target).forEach(item => {
                target[item] = reactive(target[item])
            })
        }

        return new Proxy(target, reactiveHandler)
    }
    return target
}

function throttle(fn, delay) {
    let lastTime = 0
    return function () {
        const nowTime = Date.now()
        if (nowTime - lastTime > delay) {
            fn.apply(this, arguments)
            lastTime = nowTime
        }
    }

}

function debounce(fn, delay) {
    let timer
    return function () {
        clearTimeout(timer)
        timer = setTimeout(() => {
            fn.apply(this, arguments)
            timer = null
        }, delay)
    }
}


